package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 根据条件分页查询菜品
     * @param dishPageQueryDTO
     * @return
     */
    List<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 修改菜品属性
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void update(Dish dish);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    DishVO getById(Long id);

    /**
     * 根据id删除菜品
     * @param ids
     */
    void delete(List<Integer> ids);

    /**
     * 保存菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into dish (name, category_id, price, status, description, image, create_time, update_time, create_user, update_user) " +
            "values (#{name}, #{categoryId}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void save(Dish dish);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<DishVO> list(Long categoryId);
    /**
     * 启售停售菜品
     * @param status
     * @param id
     */
    @AutoFill(OperationType.UPDATE)
    @Update("update dish set status = #{status} where id = #{id}")
    void startOrStop(Integer status, Long id);

    /**
     * 根据状态查询菜品数量
     * @param i
     * @return
     */
    @Select("select count(id) from dish where status = #{status}")
    Integer getNumByStatus(int status);

//    /**
//     * 根据分类id查询菜品
//     * @param categoryId
//     * @return
//     */
//    @Select("select * from dish where category_id = #{categoryId}")
//    List<Dish> list(Long categoryId);
}
